home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 7.2 KB | 219 lines | [TEXT/CCL2] |
- ;;; pop-up-view.lisp
- ;;;
- ;;; Paul McCartney, Spring 1992
- ;;;
- ;;; Copyright © 1992 Paul McCartney. All Rights Reserved.
- ;;;
- ;;; Washington University Medical Informatics Training Program
- ;;;
- ;;; DESCRIPTION:
- ;;;
- ;;; Pop up views are used to temporarily display graphical/textual information
- ;;; to the user. When the user clicks on an area and keeps the mouse button
- ;;; down, a view that appears like a shadow edged window is shown. Anything can
- ;;; be drawn to the pop up view at that point. When the user releases the mouse
- ;;; button, the background is restored instantaneously.
- ;;;
- ;;; USE:
- ;;;
- ;;; pop-up-view - object class (not a view). DO NOT INSTALL THIS AS A VIEW.
- ;;; :pop-up-view-size - size of pop up view
- ;;; :pop-up-view-draw-fn - function to be called to draw things to the
- ;;; pop up view; takes pop up view, view size, and
- ;;; data as arguments
- ;;; :color-list - list including:
- ;;; :background
- ;;; :foreground
- ;;; :frame - border outline color
- ;;; :shadow
- ;;;
- ;;; puv-init - initialize this module. YOU MUST CALL THIS INIT TO USE POP UP VIEWS.
- ;;; puv-destroy - free up module data
- ;;; puv-display - this function should be called in response to a mouse click
- ;;; event. The pop up view is shown and will continue to be shown
- ;;; as long as the mouse button is down.
- ;;;
- ;;; HISTORY:
- ;;;
- ;;; 7/18/92 Created. -PM
-
- (in-package :ccl)
- (use-package :oou)
-
- (require :GWorld-view)
-
- (export '(puv-init puv-destroy puv-display pop-up-view)
- :ccl)
-
-
- (defvar *puv-info*)
-
-
- (defstruct puv-store
- offscreen-storage
- onscreen-view
- onscreen-rect
- offscreen-rect)
-
-
- (defclass pop-up-view ()
- ((size :initarg :pop-up-view-size :accessor size)
- (draw-fn :initarg :pop-up-view-draw-fn :accessor draw-fn)
- (color-list :initarg :color-list :accessor color-list)
- )
- (:default-initargs
- :pop-up-view-size #@(50 50)
- :pop-up-view-draw-fn #'(lambda (view size data) (declare (ignore view size data)))
- :color-list ()
- )
- )
-
-
- (defun puv-init (&optional (size #@(200 200)))
- (let ((GWorld (make-instance 'GWorld-view
- :GW-depth 0
- :view-size size)))
- (GW-alloc GWorld)
- (setf *puv-info*
- (make-puv-store
- :offscreen-storage GWorld
- :onscreen-view (make-instance 'view)
- :onscreen-rect (make-record :rect)
- :offscreen-rect (make-record :rect))) ))
-
-
- (defun puv-destroy ()
- (GW-free (puv-store-offscreen-storage *puv-info*))
- (dispose-record (puv-store-onscreen-rect *puv-info*))
- (dispose-record (puv-store-offscreen-rect *puv-info*)))
-
-
- (defun copy-background-offscreen (view size)
- (let* ((pop-up-view (puv-store-onscreen-view *puv-info*))
- (r1 (puv-store-onscreen-rect *puv-info*))
- (r2 (puv-store-offscreen-rect *puv-info*))
- (GWorld (puv-store-offscreen-storage *puv-info*))
- (view-topleft (view-scroll-position view))
- (view-bottomright (add-points view-topleft (view-size view)))
- (mouse (view-mouse-position view))
- (top (max (point-v view-topleft)
- (min (point-v mouse) (- (point-v view-bottomright) (point-v size)))))
- (left (max (point-h view-topleft)
- (min (point-h mouse) (- (point-h view-bottomright) (point-h size)))))
- (topleft (make-point left top))
- (bottomright (add-points topleft size)))
- (rset r1 :rect.topleft topleft)
- (rset r1 :rect.bottomright bottomright)
- (rset r2 :rect.topleft #@(0 0))
- (rset r2 :rect.bottomright (subtract-points bottomright topleft))
- (with-locked-GWorld-view GWorld
- (with-focused-view view
- (with-fore-color *black-color*
- (with-back-color *white-color*
- (with-pointers ((sb (rref (wptr view) :GrafPort.portBits))
- (db (rref (wptr GWorld) :GrafPort.portBits)))
- (#_CopyBits sb db r1 r2 #$srcCopy (%null-ptr))) ))))
- (add-subviews view pop-up-view)
- (set-view-size pop-up-view size)
- (set-view-position pop-up-view topleft) ))
-
-
- (defun restore-background (view)
- (let ((pop-up-view (puv-store-onscreen-view *puv-info*))
- (r1 (puv-store-onscreen-rect *puv-info*))
- (r2 (puv-store-offscreen-rect *puv-info*))
- (GWorld (puv-store-offscreen-storage *puv-info*)))
- (remove-subviews view pop-up-view)
- (with-locked-GWorld-view GWorld
- (with-focused-view view
- (with-fore-color *black-color*
- (with-back-color *white-color*
- (with-pointers ((sb (rref (wptr GWorld) :GrafPort.portBits))
- (db (rref (wptr view) :GrafPort.portBits)))
- (#_CopyBits sb db r2 r1 #$srcCopy (%null-ptr)))
- (validate-view view)))))))
-
-
- ;;;;
- ;;;; POP UP VIEW METHODS
- ;;;;
-
- (defmethod part-color ((puv pop-up-view) part)
- (getf (color-list puv) part))
-
-
- (defmethod puv-display ((puv pop-up-view) parent-view &optional (data nil))
- (let* ((pop-up-view (puv-store-onscreen-view *puv-info*))
- (window-view (view-window parent-view)))
- (copy-background-offscreen window-view (size puv))
- (puv-draw puv pop-up-view data)
- (do () ((not (mouse-down-p))))
- (restore-background window-view) ))
-
-
- (defmethod puv-draw ((puv pop-up-view) view data)
- (let* ((back-topleft #@(2 2))
- (back-bottomright (size puv))
- (front-topleft #@(0 0))
- (front-bottomright (subtract-points (size puv) #@(2 2)))
- (right (point-h (size puv)))
- (bottom (point-v (size puv))))
- (with-GWorld-no-colorization (view 0 0 right bottom #$srcCopy)
- (with-back-color (or (part-color puv :background) *white-color*)
- (with-fore-color (or (part-color puv :shadow) *black-color*)
- (rlet ((r :rect :topleft back-topleft :bottomright back-bottomright))
- (#_PaintRect r)))
- (rlet ((r :rect :topleft front-topleft :bottomright front-bottomright))
- (#_EraseRect r)
- (with-fore-color (or (part-color puv :frame) *black-color*)
- (#_FrameRect r))
- (with-fore-color (or (part-color puv :foreground) *black-color*)
- (funcall (draw-fn puv) *GW-offscreen-view* (size puv) data))))) ))
-
-
- (provide :pop-up-view)
-
-
- #|
- ; Example
-
- (require :quickdraw)
-
- (puv-init)
- ;(puv-destroy)
-
- (defclass foo-window (window)
- ()
- (:default-initargs
- :view-size #@(300 300)
- :color-p t
- )
- )
-
- (defun draw-a-circle (view size data)
- (declare (ignore size data))
- (with-fore-color *red-color*
- (paint-oval view #@(20 20) #@(50 50)) ))
-
- (defvar *color-puv*
- (make-instance 'pop-up-view
- :pop-up-view-size #@(100 100)
- :pop-up-view-draw-fn #'draw-a-circle
- :color-list (list :background *yellow-color*
- :frame *light-blue-color*
- :shadow *blue-color*)))
-
- (defmethod view-draw-contents ((view foo-window))
- (dotimes (i 60)
- (with-fore-color (random most-positive-fixnum)
- (move-to view 10 (+ 20 (* i 2)))
- (line-to view 100 (+ 20 (* i 4)))))
- (move-to view 10 20)
- (format view "Click here.") )
-
- (defmethod view-click-event-handler ((view foo-window) where)
- (puv-display *color-puv* view))
-
- (setf w (make-instance 'foo-window))
- |#
-